package com.ruoyi.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;

import java.util.List;

/**
 * 6.1 流程定义的查询
 */
public class QueryProcessDefinition {

    public static void main(String[] args) {
        queryProcess();
    }


    ///查询流程
    public static  void queryProcess()
    {
        System.out.println("...定义流程的查询...");
        //1.获取ProcessEngine引擎对象
        ProcessEngine processEngine =
                ProcessEngines.getDefaultProcessEngine();
        //2.创建RepositoryService对象
        RepositoryService repositoryService = processEngine.getRepositoryService();
        //3.获取ProcessDefinitionQuery对象
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
        //4.设置条件，并且查询出当前的所有流程的定义,查询条件：流程定义的key=holiday 设置排序方式

        List<ProcessDefinition> holiday =
                processDefinitionQuery.processDefinitionKey("myProcess_1").//holiday").
                        orderByProcessDefinitionVersion().
                        desc().list();
        //5.输出流程定义的信息
        for (ProcessDefinition processDefinition : holiday) {
            System.out.println("流程定义的ID" + processDefinition.getId()
                    +"，流程定义的名称" + processDefinition.getName()
                    +"，流程定义的key" + processDefinition.getKey()
                    +"，流程定义的版本" + processDefinition.getVersion());
        }
    }

}